Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve comments about type folding/visiting. #93758

Merged
merged 1 commit into from
Feb 18, 2022

Conversation

nnethercote
Copy link
Contributor

I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.

This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. Ty, Predicate,
Region, Const) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.

The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one impl to a better place.

r? @BoxyUwU

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 8, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2022
compiler/rustc_middle/src/ty/fold.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/fold.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/fold.rs Show resolved Hide resolved
@nnethercote
Copy link
Contributor Author

@BoxyUwU Thanks for the comments. I have addressed them and updated the code.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 16, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Feb 16, 2022

📌 Commit 2e56c02 has been approved by BoxyUwU

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 16, 2022
@nnethercote
Copy link
Contributor Author

@bors rollup=always

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 16, 2022
…s, r=BoxyUwU

Improve comments about type folding/visiting.

I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.

This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.

The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.

r? `@BoxyUwU`
@matthiaskrgr
Copy link
Member

doctest failure #94065 (comment)
@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 17, 2022
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 17, 2022

intra doc link checker stuff really ought to go into normal CI :(

I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.

This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.

The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.
@nnethercote
Copy link
Contributor Author

I fixed the link bustage.

@bors r=BoxyUwU

@bors
Copy link
Contributor

bors commented Feb 17, 2022

📌 Commit 94f0849 has been approved by BoxyUwU

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#93337 (Update tracking issue numbers for inline assembly sub-features)
 - rust-lang#93758 (Improve comments about type folding/visiting.)
 - rust-lang#93780 (Generate list instead of div items in sidebar)
 - rust-lang#93976 (Add MAIN_SEPARATOR_STR)
 - rust-lang#94011 (Even more let_else adoptions)
 - rust-lang#94041 (Add a `try_collect()` helper method to `Iterator`)
 - rust-lang#94043 (Fix ICE when using Box<T, A> with pointer sized A)
 - rust-lang#94082 (Remove CFG_PLATFORM)
 - rust-lang#94085 (Clippy: Don't lint `needless_borrow` in method receiver positions)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 98c54c8 into rust-lang:master Feb 18, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 18, 2022
@nnethercote nnethercote deleted the improve-folding-comments branch February 18, 2022 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants